package com.example.collectiondemo.list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ThreeIterator {
    public static void main(String[] args) {
        List<Integer> Test = new ArrayList<Integer>();
        for (int i = 0; i < 100000000; i++) {
            Test.add(4);
        }

        Long a1 = System.currentTimeMillis();
        //普通的for
        int size = Test.size();
        for (int i = 0; i < size; i++) { }
        Long a2 = System.currentTimeMillis();
        //for增强版
        for (Integer integer : Test) { }
        Long a3 = System.currentTimeMillis();
        //iterator
        Iterator<Integer> iterator = Test.iterator();
        while (iterator.hasNext()){
            iterator.next();
        }
        Long a4 = System.currentTimeMillis();

        System.out.println("普通的for==================="+ (a2 - a1));
        System.out.println("for增强版==================="+ (a3 - a2));
        System.out.println("iterator==================="+ (a4 - a3));
    }

}
